
import daisy.lang._
import Real._

/*
  These benchmarks were used by the Real2Float tool,

  Optimization problems from A Numerical Evaluation of
  Several Stochastic Algorithms on Selected Continuous
  Global Optimization problems,
  Ali, Khompatraporn, Zabinsky, 2005)

*/
object Hartman {

  def hartman3(x1: Real, x2: Real, x3: Real): Real = {
    require(0 <= x1 && x1 <= 1 && 0 <= x2 && x2 <= 1 && 0 <= x3 && x3 <= 1)

    val e1 = 3.0*(x1 - 0.3689)*(x1 - 0.3689) + 10.0*(x2 -0.117)*(x2 -0.117) +
      30.0 * (x3 - 0.2673)*(x3 - 0.2673)
    val e2 = 0.1*(x1 -0.4699)*(x1 -0.4699) + 10.0*(x2 -0.4387)*(x2 -0.4387) +
      35.0 * (x3 - 0.747)*(x3 - 0.747)
    val e3 = 3.0*(x1 -0.1091)*(x1 -0.1091) + 10.0*(x2 -0.8732)*(x2 -0.8732) +
      30.0 * (x3 - 0.5547)*(x3 - 0.5547)
    val e4 = 0.1*(x1 -0.03815)*(x1 -0.03815) + 10.0 * (x2 -0.5743)*(x2 -0.5743) +
      35.0 * (x3 - 0.8828)*(x3 - 0.8828)

    -(1.0 * exp(-e1) + 1.2 * exp(-e2) + 3.0 * exp(-e3) + 3.2 * exp(-e4))

  } //2.99e–13

  def hartman6(x1: Real, x2: Real, x3: Real, x4: Real, x5: Real, x6: Real): Real = {
    require(0 <= x1 && x1 <= 1 && 0 <= x2 && x2 <= 1 && 0 <= x3 && x3 <= 1 &&
      0 <= x4 && x4 <= 1 && 0 <= x5 && x5 <= 1 && 0 <= x6 && x6 <= 1)

    val e1 = 10.0*(x1 -0.1312)*(x1 -0.1312) + 3.0*(x2 -0.1696)*(x2 -0.1696) +
      17.0*(x3 -0.5569)*(x3 -0.5569) + 3.5*(x4 -0.0124)*(x4 -0.0124) +
        1.7*(x5 -0.8283)*(x5 -0.8283) + 8.0*(x6 -0.5886)*(x6 -0.5886)

    val e2 = 0.05*(x1 -0.2329)*(x1 -0.2329) + 10.0*(x2 -0.4135)*(x2 -0.4135) +
      17.0*(x3 -0.8307)*(x3 -0.8307) + 0.1*(x4 -0.3736)*(x4 -0.3736) +
      8.0*(x5 -0.1004)*(x5 -0.1004) + 14.0*(x6 -0.9991)*(x6 -0.9991)

    val e3 = 3.0*(x1 -0.2348)*(x1 -0.2348) + 3.5*(x2 -0.1451)*(x2 -0.1451) +
      1.7*(x3 -0.3522)*(x3 -0.3522) + 10.0*(x4 -0.2883)*(x4 -0.2883) +
        17.0*(x5 -0.3047)*(x5 -0.3047) + 8.0*(x6 -0.665)*(x6 -0.665)

    val e4 = 17.0*(x1 -0.4047)*(x1 -0.4047) + 8.0*(x2 -0.8828)*(x2 -0.8828) +
      0.05*(x3 -0.8732)* (x3 -0.8732) + 10.0 * (x4 -0.5743)* (x4 -0.5743) +
        0.1*(x5 -0.1091)*(x5 -0.1091) + 14.0 * (x6 -0.0381)*(x6 -0.0381)

    -(1.0 * exp(-e1) + 1.2 * exp(-e2) + 3.0 * exp(-e3) + 3.2 * exp(-e4))
  } //5.09e–13

}

